package com.fengniu.ejb.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 * 
 * @author conan
 * 
 * http://docs.jboss.org/ejb3/app-server/tutorial/clusteredentity/clusteredentity.html
 * This defines that Category should be cached. Any attempt to look up Category
 * by its primary key, will first attempt to read the entry from the cache. If
 * it cannot be found it will load it up from the database.
 * 
 * http://technology.amis.nl/blog/?p=1363 EJB 3.0 Java Persistence API - refresh
 * After Insert: Using EntityListeners to absorb the effects from Database
 * Triggers by Lucas Jellema
 */
@Entity
@Table(name = "CategoryTable", schema = "FENGNIU", uniqueConstraints = {})
@NamedQueries( {
		@NamedQuery(name = "CategoryDao.eql.getListCategoryByCategoryId", query = "SELECT g FROM Category g WHERE g.categoryId=:categoryId"),
		@NamedQuery(name = "CategoryDao.eql.getListChildCategoryBy", query = "SELECT p FROM Category p WHERE p.primaryParent.categoryId=:parentCategoryId") })
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
public class Category extends GeneEntity implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 4553483823098511037L;

	@Column(nullable = false, unique = true, updatable = false)
	private String categoryId; // manual defined unique id for the category

	private String name;

	private String fullName;

	private String smallImageName;

	// private String type;

	@ManyToOne
	Category primaryParent;

	// You can add optimistic locking capability to an entity bean using the
	// @Version annotation:
	// this below will cause Unable to define/override @Version on a subclass if
	// you extends GeneEntity but will not if you use MappedClass of GeneEntity
	// @Version
	// @Column(name = "OPTLOCK")
	// private Integer version;

	public Category() {

	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(String categoryId) {
		this.categoryId = categoryId;
	}

	public Category getPrimaryParent() {
		return primaryParent;
	}

	public void setPrimaryParent(Category primaryParent) {
		this.primaryParent = primaryParent;
	}

	public String getFullName() {
		return fullName;
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	public String getSmallImageName() {
		return smallImageName;
	}

	public void setSmallImageName(String smallImageName) {
		this.smallImageName = smallImageName;
	}

}
